<?php
/**
 * Created by PhpStorm.
 * User: john
 * Time: 上午2:45
 */

namespace app\core\exception;

use app\ExceptionHandle;
use think\Response;

class ApiHandleException extends ExceptionHandle
{

    /**
     * http 状态码
     * @var int
     */
    public $httpCode = 500;


    public function render($request, \Throwable $e): Response
    {

        if ($e instanceof ApiException) {
            $this->httpCode = $e->httpCode;
            return res($e->getCode(), $e->getMessage(), $e->data, $this->httpCode);
        }

        if (config('app.show_error_msg') == true) {
            return parent::render($request, $e);
        }
        return res(NET_ERROR, $e->getMessage(), [], $this->httpCode);
    }
}